package com.lanou.beautifulwardrobe.Home.Adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.lanou.beautifulwardrobe.entify.RecommedImage;
import com.lanou.beautifulwardrobe.factory.RecommendImageFragment;

import java.util.List;

/**
 * Created by dllo on 15/10/22.
 */
public class HomeRecommendViewPagerAdapter extends FragmentPagerAdapter {
    private List<RecommedImage> datas;

    public void addData(List<RecommedImage> recommedImages) {
        datas = recommedImages;
        notifyDataSetChanged();

    }

    public HomeRecommendViewPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        RecommedImage recommedImage=datas.get(position);
        String imageUrl=recommedImage.getPic_url();
        String url =recommedImage.getUrl();
        String temp[]=url.split("=");
        String id=temp[1];
        return RecommendImageFragment.getInstance(imageUrl,id);
    }

    @Override
    public int getCount() {
        return datas!=null&&datas.size()>0?datas.size():0;
    }


}
